<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">




<xsl:template match="admin-appointments" mode="admin-archives-all">
	<xsl:choose>
		<xsl:when test="admin-edit-appointment/@result = 'error'">
			<p>Errors</p>
		</xsl:when>
		<xsl:when test="admin-appointments/error = 'No records found.'">
			<p>It's hard to believe, but there aren't any past appointments yet.</p>
		</xsl:when>
		<xsl:otherwise>
			<form method="post" action="" enctype="multipart/form-data">
				<div>
					<table id="pricingTable" cellpadding="0" cellspacing="0">
						<thead>
							<tr>
								<th class="table-th-sort-rev">App. <br />Date</th>
								<th>Name <br /> (Last, First)</th>
								<th>Client <br />Username</th>
								<th class="table-th-nosort">Payment <br />Status</th>
								<th class="table-th-nosort">Payment <br />Method</th>
								<th class="table-th-nosort">Charge</th>
								<th class="table-th-nosort">Ins. <br />Coverage</th>
								<th class="table-th-nosort">Patient <br />Resp.</th>
								<th class="table-th-nosort">Patient <br />Pymt.</th>
								<th class="table-th-nosort">Bal.</th>
							</tr>
						</thead>
						<tbody>
							<xsl:apply-templates select="entry" mode="tr"/>
						</tbody>
					</table>
					<p id="admin_archive_submit"><a href="{$root}/{$root-page}/" id="admin_archive_cancel">Discard All Changes</a> <input name="action[admin-edit-appointment]" type="submit" value="Save Changes" id="admin_archive_save" /></p>
				</div>
			</form>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-appointments/entry" mode="tr">
	<tr class="allUserPrices" id="admin_archives_{@id}">
<!-- here here
	<td class="appointment-username">
		<xsl:value-of select="position() - 1"/>
	</td>
 here here -->
		<xsl:apply-templates select="." mode="td">
			<xsl:with-param name="array" select="position() - 1"/>
		</xsl:apply-templates>
	</tr>
</xsl:template>

<xsl:template match="admin-appointments/entry" mode="td">
	<xsl:param name="array"/>
	
	<td class="appointment-date">
		<xsl:value-of select="appointment-date"/>
		<xsl:text> </xsl:text>
		<br />
		<xsl:call-template name="get-formatted-time">
			<xsl:with-param name="time" select="appointment-date/@time"/>
		</xsl:call-template>
	</td>
	<td class="appointment-name">
		<xsl:value-of select="name"/>
	</td>
	<td class="appointment-username">
		<xsl:value-of select="email"/>
	</td>
	<td class="payment-status-{payment-status/item/@handle}">
		<select name="fields[{$array}][payment-status]">
			<xsl:choose>
				<xsl:when test="payment-status/item = 'Pending'">
					<option value="Pending" selected="selected">Pending</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Pending">Pending</option>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="payment-status/item = 'Due'">
					<option value="Due" selected="selected">Due</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Due">Due</option>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="payment-status/item = 'Paid'">
					<option value="Paid" selected="selected">Paid</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Paid">Paid</option>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="payment-status/item = 'Past Due'">
					<option value="Past Due" selected="selected">Past Due</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Past Due">Past Due</option>
				</xsl:otherwise>
			</xsl:choose>
		</select>
	</td>
	<td class="pay_status_method">
		<select name="fields[{$array}][payment-method]" id="{$array}-payment-status">
			<xsl:choose>
				<xsl:when test="payment-method/item = 'None'">
					<option value="None" selected="selected">None</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="None">None</option>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="payment-method/item = 'Cash'">
					<option value="Cash" selected="selected">Cash</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Cash">Cash</option>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="payment-method/item = 'Credit Card'">
					<option value="Credit Card" selected="selected">Credit Card</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Credit Card">Credit Card</option>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="payment-method/item = 'Check'">
					<option value="Check" selected="selected">Check</option>
				</xsl:when>
				<xsl:otherwise>
					<option value="Check">Check</option>
				</xsl:otherwise>
			</xsl:choose>
		</select>
	</td>
	<td>
		<ins><input class="charge" id="{$array}-charge" name="fields[{$array}][charge]" type="text" value="{charge}" /></ins>
	</td>
	<td>
		<ins><input class="insurance-payment" id="{$array}-insurance-payment" name="fields[{$array}][insurance-payment]" type="text" value="{insurance-payment}" /></ins>
	</td>
	<td>
		<ins><input class="patient-responsibility" id="{$array}-patient-responsibility" name="fields[{$array}][patient-responsibility]" type="text" value="{patient-responsibility}" /></ins>
	</td>
	<td>
		<ins><input class="patient-payment" id="{$array}-patient-payment" name="fields[{$array}][patient-payment]" type="text" value="{patient-payment}" /></ins>
	</td>
	<td>
		<ins><input class="client-balance" id="{$array}-balance" name="fields[{$array}][balance]" type="text" value="{balance}" /></ins>
		<!--xsl:value-of select="balance"/-->
		<!--ins><input name="fields[{$array}][charge]" type="text" value="{balance}" /></ins-->
		<input name="id[{$array}]" type="hidden" value="{@id}" />
	</td>
</xsl:template>

<xsl:template match="/data/admin-clients" mode="admin-archives-client-list">
	<select id="admin_archives_client">
		<option value="All">All Clients</option>
		<option disabled="disabled" value="">--------------</option>
		<xsl:apply-templates select="entry" mode="archives-client-list"/>
	</select>
</xsl:template>

<xsl:template match="/data/admin-clients" mode="admin-archives-payment-status-list">
	<select id="admin_archives_payment_status">
		<xsl:choose>
			<xsl:when test="$payment = 'all'">
				<option value="all" selected="selected">All Payment Status Types</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="all">All Payment Status Types</option>
			</xsl:otherwise>
		</xsl:choose>
		<option disabled="disabled" value="">--------------</option>
		<xsl:choose>
			<xsl:when test="$payment = 'pending'">
				<option value="pending" selected="selected">Pending</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="pending">Pending</option>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="$payment = 'due'">
				<option value="due" selected="selected">Due</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="due">Due</option>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="$payment = 'past-due'">
				<option value="past-due" selected="selected">Past Due</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="past-due">Past Due</option>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="$payment = 'paid'">
				<option value="paid" selected="selected">Paid</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="paid">Paid</option>
			</xsl:otherwise>
		</xsl:choose>
	</select>
</xsl:template>

<xsl:template match="/data/admin-clients/entry" mode="archives-client-list">
	<xsl:choose>
		<xsl:when test="email-address/@handle = $entry-id">
			<option value="{email-address/@handle}" selected="selected">
				<xsl:value-of select="last-name"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="first-name"/>
			</option>
		</xsl:when>
		<xsl:otherwise>
			<option value="{email-address/@handle}">
				<xsl:value-of select="last-name"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="first-name"/>
			</option>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>




<xsl:template match="admin-appointments" mode="admin-archives-client">
	<xsl:param name="selected-client">
		<xsl:for-each select="/data/admin-clients/entry[email-address/@handle = $entry-id]">
			<xsl:value-of select="email-address"/>
		</xsl:for-each>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="admin-appointments/error = 'No records found.'">
			<p>It's hard to believe, but there aren't any past appointments yet.</p>
		</xsl:when>
		<xsl:otherwise>
			<form method="post" action="" enctype="multipart/form-data">
				<div>
				    <table id="pricingTable" cellpadding="0" cellspacing="0">
				        <thead>
				        <tr>
				            <th class="sortBy">Appointment <br />Date</th>
							<th>Name <br /> (Last, First)</th>
				            <th>Client <br />Username</th>
				            <th class="table-th-nosort">Payment <br />Status</th>
				            <th class="table-th-nosort">Payment <br />Method</th>
				            <th class="table-th-nosort">Charge</th>
				            <th class="table-th-nosort">Insurance <br />Coverage</th>
				            <th class="table-th-nosort">Patient <br />Responsibility</th>
				            <th class="table-th-nosort">Patient <br />Payment</th>
				            <th class="table-th-nosort">Balance</th>
				        </tr>
				        </thead>
				        <tbody>
							<xsl:apply-templates select="entry[email = $selected-client]" mode="tr-single">
								<xsl:with-param name="the-client" select="$selected-client"/>
								<xsl:with-param name="array" select="position() - 1"/>
							</xsl:apply-templates>
				        </tbody>
					</table>
					<p id="admin_archive_submit"><a href="{$root}/{$root-page}/{$entry-id}/" id="admin_archive_cancel">Discard All Changes</a> <input name="action[admin-edit-appointment]" type="submit" value="Save Changes" id="admin_archive_save" /></p>
				</div>
			</form>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-appointments" mode="admin-archives-payment">
	<xsl:param name="selected-client">
		<xsl:for-each select="/data/admin-clients/entry[@id = $entry-id]">
			<xsl:value-of select="email-address"/>
		</xsl:for-each>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="admin-appointments/error = 'No records found.'">
			<p>It's hard to believe, but there aren't any past appointments yet.</p>
		</xsl:when>
		<xsl:otherwise>
			<form method="post" action="" enctype="multipart/form-data">
				<div>
				    <table id="pricingTable" cellpadding="0" cellspacing="0">
				        <thead>
				        <tr>
				            <th class="sortBy">cAppointment <br />Date</th>
							<th>Name <br /> (Last, First)</th>
				            <th>Client <br />Username</th>
				            <th class="table-th-nosort">Payment <br />Status</th>
				            <th class="table-th-nosort">Payment <br />Method</th>
				            <th class="table-th-nosort">Charge</th>
				            <th class="table-th-nosort">Insurance <br />Coverage</th>
				            <th class="table-th-nosort">Patient <br />Responsibility</th>
				            <th class="table-th-nosort">Patient <br />Payment</th>
				            <th class="table-th-nosort">Balance</th>
				        </tr>
				        </thead>
				        <tbody>
							<xsl:apply-templates select="entry[payment-status/item/@handle = $payment]" mode="tr-single">
								<xsl:with-param name="the-client" select="$selected-client"/>
								<xsl:with-param name="array" select="position() - 1"/>
							</xsl:apply-templates>
				        </tbody>
					</table>
					<p id="admin_archive_submit"><a href="{$root}/{$root-page}/{$entry-id}/" id="admin_archive_cancel">Discard All Changes</a> <input name="action[admin-edit-appointment]" type="submit" value="Save Changes" id="admin_archive_save" /></p>
				</div>
			</form>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-appointments" mode="admin-archives-both">
	<xsl:param name="selected-client">
		<xsl:for-each select="/data/admin-clients/entry[@id = $entry-id]">
			<xsl:value-of select="email-address"/>
		</xsl:for-each>
	</xsl:param>
	<xsl:choose>
		<xsl:when test="admin-appointments/error = 'No records found.'">
			<p>It's hard to believe, but there aren't any past appointments yet.</p>
		</xsl:when>
		<xsl:otherwise>
			<form method="post" action="" enctype="multipart/form-data">
				<div>
				    <table id="pricingTable" cellpadding="0" cellspacing="0">
				        <thead>
				        <tr>
				            <th class="sortBy">cAppointment <br />Date</th>
							<th>Name <br /> (Last, First)</th>
				            <th>Client <br />Username</th>
				            <th class="table-th-nosort">Payment <br />Status</th>
				            <th class="table-th-nosort">Payment <br />Method</th>
				            <th class="table-th-nosort">Charge</th>
				            <th class="table-th-nosort">Insurance <br />Coverage</th>
				            <th class="table-th-nosort">Patient <br />Responsibility</th>
				            <th class="table-th-nosort">Patient <br />Payment</th>
				            <th class="table-th-nosort">Balance</th>
				        </tr>
				        </thead>
				        <tbody>
							<xsl:apply-templates select="entry[email = $selected-client and payment-status/item/@handle = $payment]" mode="tr-single">
								<xsl:with-param name="the-client" select="$selected-client"/>
								<xsl:with-param name="array" select="position() - 1"/>
							</xsl:apply-templates>
				        </tbody>
					</table>
					<p id="admin_archive_submit"><a href="{$root}/{$root-page}/{$entry-id}/" id="admin_archive_cancel">Discard All Changes</a> <input name="action[admin-edit-appointment]" type="submit" value="Save Changes" id="admin_archive_save" /></p>
				</div>
			</form>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-appointments/entry" mode="tr-single">
	<xsl:param name="the-client"/>
	
	<tr class="allUserPrices" id="{@id}">
		<xsl:apply-templates select="." mode="td">
			<xsl:with-param name="array" select="position() - 1"/>
		</xsl:apply-templates>
	</tr>
</xsl:template>

<xsl:template match="admin-appointments/entry" mode="td-single">
	<td class="appointment-date">
		<xsl:value-of select="appointment-date"/>
	</td>
	<td class="appointment-name">
		<xsl:value-of select="name"/>
	</td>
	<td class="appointment-username">
		<xsl:value-of select="email"/>
	</td>
	<td class="payment-status-{payment-status/item/@handle}">
		<xsl:value-of select="payment-status/item"/>
	</td>
	<td class="pay_status_method">
		<xsl:value-of select="payment-method/item"/>
	</td>
	<td>
		<xsl:value-of select="charge"/>
	</td>
	<td>
		<xsl:value-of select="insurance-payment"/>
	</td>
	<td>
		<xsl:value-of select="patient-responsibility"/>
	</td>
	<td>
		<xsl:value-of select="patient-payment"/>
	</td>
	<td>
		<xsl:value-of select="balance"/>
	</td>
</xsl:template>

</xsl:stylesheet>





	<!--xsl:choose>
		<xsl:when test="/data/clients/entry/administrator = 'Yes'">
			<div class="grid_16">
				<div class="grid_5 alpha">
					<xsl:call-template name="admin-menu"/>
				</div>
				<div class="grid_11 omega" id="archives">
					<div class="calendar-head">
						<h2>Client Payment Management</h2>
						<xsl:choose>
							<xsl:when test="admin-appointments/error = 'No records found.'">
								<p>It's hard to believe, but there aren't any past appointments yet.</p>
							</xsl:when>
							<xsl:otherwise>
								
							</xsl:otherwise>
						</xsl:choose>
					</div>
				</div>
			</div>
		</xsl:when>
		<xsl:otherwise>
			<div class="grid_16">
				<div class="grid_11 omega" id="archives">
					<h2>Past Appointments</h2>
					<xsl:choose>
						<xsl:when test="past-client-appointments-long/error = 'No records found.'">
							<p>You have no past appointments yet; once you do, you'll be able to view them here.</p>
						</xsl:when>
						<xsl:otherwise>
							<p>Your current outstanding balance is: 
								<em id="client_balance_1"></em>
							</p>
						    <table id="pricingTable" cellpadding="0" cellspacing="0">
						        <thead>
						        <tr>
						            <th class="sortBy">Appointment <br />Date</th>
						            <th>Payment <br />Status</th>
						            <th>Payment <br />Method</th>
						            <th>Charge</th>
						            <th>Insurance <br />Coverage</th>
						            <th>Patient <br />Responsibility</th>
						            <th>Patient <br />Payment</th>
						            <th>Balance</th>
						        </tr>
						        </thead>
						        <tbody>
									<xsl:apply-templates select="past-client-appointments-long/entry" mode="tr"/>
						        </tbody>
						    </table>
						    <table id="balance_total" cellpadding="0" cellspacing="0">
						        <tbody>
									<tr>
										<td colspan="7">Total</td>
										<td id="client_balance_2"></td>
									</tr>
						        </tbody>
						    </table>
							<xsl:call-template name="outstanding-balance"/>
						</xsl:otherwise>
					</xsl:choose>
				</div>
			</div>
		</xsl:otherwise>
	</xsl:choose-->
	
<!--xsl:template name="outstanding-balance">
	<script type="text/javascript">
		var total = <xsl:apply-templates select="past-client-appointments-long/entry" mode="balance"/>;
		total = "$" + (total).numberFormat(2, '.', ',');
		$('client_balance_1').set('html',total);
		$('client_balance_2').set('html',total);
	</script>
</xsl:template>
<xsl:template match="past-client-appointments-long/entry" mode="balance">
	<xsl:choose>
		<xsl:when test="payment-status/item/@handle = 'pending'">
			<xsl:text>0</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="number(balance)"/>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:if test="position() &lt; last()">
		<xsl:text>+</xsl:text>
	</xsl:if>
</xsl:template>

<xsl:template match="past-client-appointments-long/entry" mode="tr">
	<tr class="allUserPrices" id="{@id}">
		<xsl:apply-templates select="." mode="td"/>
	</tr>
</xsl:template>

<xsl:template match="past-client-appointments-long/entry" mode="td">
	<td class="appointment-date">
		<xsl:value-of select="appointment-date"/>
	</td>
	<td class="payment-status-{payment-status/item/@handle}">
		<xsl:value-of select="payment-status/item"/>
	</td>
	<td class="pay_status_method">
		<xsl:value-of select="payment-method/item"/>
	</td>
	<td>
		<xsl:value-of select="charge"/>
	</td>
	<td>
		<xsl:value-of select="insurance-payment"/>
	</td>
	<td>
		<xsl:value-of select="patient-responsibility"/>
	</td>
	<td>
		<xsl:value-of select="patient-payment"/>
	</td>
	<td>
		<xsl:value-of select="balance"/>
	</td>
</xsl:template-->